<extend name="Public:base" />
<!-- 网站标题 -->
<block name="title">页面管理</block>
<block name="appendheader">
    
	<!-- 删除确认插件 --> 
	<script type="text/javascript" src="__PUBLIC__/artDialog/jquery.artDialog.js?skin=default"></script> 
	<script type="text/javascript" src="__PUBLIC__/artDialog/iframeTools.js"></script> 
	<script type="text/javascript" src="__PUBLIC__/common/js/list.js"></script>
	
	<!-- Validform_v5.3.2验证框架 -->
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Validform/css/Validform_v5.3.2.css"/>
	<script type="text/javascript" src="__PUBLIC__/Validform/js/Validform_v5.3.2_min.js"></script>
	
	<!-- 拖动排序放于tooltip之前，否则会影响 -->
	<script type="text/javascript" src="__PUBLIC__/common/js/jquery-ui.js"></script>
	
	<!-- 弹出提示插件 -->
	<script src="__PUBLIC__/bootstrap/js/tooltip.js"></script>
	
	<!--编辑器js引入-->
	<script type="text/javascript">
		var UEDITOR_HOME_URL = '__PUBLIC__/ueditor/',ueditor_loader={};
		var MEDIA_OBJID = 'Web/{$Think.cookie.webid}{$Think.config.UEDITOR_PATH}';
	</script>
	<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script> 
     
	<!-- 选中当前菜单引入 -->
	<script type="text/javascript">
		$(function() {
			$("#WebMenu-2000").addClass('active');	//选中父菜单
			$("#WebMenu-2009").addClass('active');	//选中当前菜单
		});
	</script>
	
	<script type="text/javascript">
		//选中左侧菜单
		$(function () {
			

			$("span.option-move").bind('mouseover',function() {
				$(this).css("cursor", "move");
			});
			//普通选项退拽排序
			$(".general-option").sortable({
				axis:'y',
				opacity: 0.6,
				revert: true,
				cursor: 'move',
				handle: '.option-move'
			});
			
			//tooltip提示工具
			
			$('[data-toggle="tooltip"]').tooltip();
		});
		
	
		$(function() {
			var editor;
			var myform=$("#myform").Validform({
				tiptype:3,
				label:".label",
				showAllError:true,
				postonce:true,//开启二次提交防御
				ajaxPost:false,
				beforeSubmit:function(curform) {
					//在验证成功后，表单提交前执行的函数，curform参数是当前表单对象。
					lockScreen();
				},
				callback:function(data){
					$.Hidemsg();
				}
			});
			myform.addRule([{
				ele:"#score",
				datatype:"/^[0-9]+.?[0-9]*$/",
		        nullmsg:"必须为数字，可以有小数"
			},
			{
				ele:"#code",
				datatype:"*",
				nullmsg:"代码不能为空"
			}]);
		});
		
		//移除一般选项插件
		function minuGeneralOption(Obj) {
			$(Obj).parents(".form-group").remove();
		}
		
		//提交时检测表单数据合法性
		function check_form() {
			//对正确答案的处理
			var correct_option_obj = $("input[type='checkbox'][name='correct_option[]']");
			var selectFlag = 0;	//标记当前有多少个选项被选中
			var selectStr = '';
			$.each(correct_option_obj, function(i, e) {      
				if($(e).attr('checked') == 'checked') {
					//根据选中的正确答案改变相应的隐藏域
					//$("input[name='is_correct[]']").eq(i).val('b');
					selectStr = selectStr + i + ',';
					++selectFlag;	//选中项的数据自增1
				}
			});
			for(var i = 0; i < correct_option_obj.length; i++) {
				if(selectStr.indexOf(i) >= 0) {
					$("input[name='is_correct[]']").eq(i).val('b');
				} else {
					$("input[name='is_correct[]']").eq(i).val('a');
				}
			}
			//单选题只能选中一个正确答案
			if(selectFlag == 0) {
				art.dialog.alert("请选择正确答案！");
				return false;
			} else if($("input[name='type']:checked").val() == 'a' && selectFlag > 1) {
				art.dialog.alert("单选题只能有一个正确答案！");
				return false;
			}
			//对题项内项内互斥的处理
			var mutual_option_obj = $("input[type='checkbox'][name='mutual_option[]']");
			selectStr = '';
			$.each(mutual_option_obj, function(i, e) {      
				if($(e).attr('checked') == 'checked') {
					//根据选中的正确答案改变相应的隐藏域
					//$("input[name='is_mutual[]']").eq(i).val('b');
					selectStr = selectStr + i + ',';
				}
			});
			for(var i = 0; i < mutual_option_obj.length; i++) {
				if(selectStr.indexOf(i) >= 0) {
					$("input[name='is_mutual[]']").eq(i).val('b');
				} else {
					$("input[name='is_mutual[]']").eq(i).val('a');
				}
			}
			return true;
		}
		
		//添加一般选项插件
		function plusGeneralOption(Obj) {
			var str = '<div class="form-group">';
				str += '<label class="col-md-2 control-label">选项<span class="require">*</span></label>';
				str += '<div class="col-md-8">';
				str += '<div class="input-group">';
				str += '<span class="input-group-addon option-move"><i class="glyphicon glyphicon-resize-vertical"></i></span>';
				str += '<input type="text" name="select_item[]" class="form-control" />';
				str += '<span class="input-group-addon">';
				str += '<label style="margin:0">';
				str += '<input type="text" name="score_option[]" style="margin:0;padding:0;width:50px;height:20px;border:1px solid #e5e5e5;"/>&nbsp;分值';
				str += '</label>';
				str += '</span>';
				str += '<span class="input-group-addon">';
				str += '<label style="margin:0">';
				str += '<input type="checkbox" name="correct_option[]"  />&nbsp;正确答案';
				str += '<input type="hidden" name="is_correct[]" value="a" />';
				str += '</label>';
				str += '</span>';
				str += '<span class="input-group-addon">';
				str += '<label style="margin:0">';
				str += '<input type="checkbox" name="mutual_option[]"  />&nbsp;项内互斥';
				str += '<input type="hidden" name="is_mutual[]" value="a" />';
				str += '</label>';
				str += '</span>';
				str += '</div>';
				str += '</div>';
				str += '<div class="col-md-2">';
				str += '<p class="form-control-static">';
				str += '<a href="javascript:void(0)" onclick="plusGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="继续添加"><i class="fa fa-plus"></i></a>&nbsp;&nbsp;';
				str += '<a href="javascript:void(0)" onclick="minuGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="删除选项"><i class="fa fa-trash-o"></i></a>';
				str += '</p>';
				str += '</div>';
				str += '</div>';
			$(Obj).parents(".form-group").after(str);
		}
	</script>
</block>
<!-- 当前位置 -->
<block name="breadcrumb">
	<div class="page-header pull-left">
		<div class="page-title">问卷管理</div>
	</div>
	<ol class="breadcrumb page-breadcrumb pull-left">
		<li><i class="fa fa-home"></i>&nbsp;<a href="__APP__?g=Admin">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
		<li><a href="#">基础数据</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
		<li class="active">问卷管理</li>
	</ol>
</block>
<block name="main_content">
	<div class="panel panel-default">
		<div class="panel-heading clearfix" >
			<h3 class="mts pull-left">添加选择题</h3>
			<div class="btn-add-content" style="text-align: right;">
				<a href="__APP__?g={:GROUP_NAME}&m=QuestionTestEdit&a=index&formid={$Think.request.formid}&mode=edit" class="btn btn-success "><i class="fa fa-reply"></i>返回问卷预览</a>&nbsp;&nbsp;
			</div>
		</div>
		<div class="panel-body mt-15">
			<form id="myform" action="__APP__?g=Admin&m=QuestionTestSelect&mode=edit&a=insert" onsubmit="return check_form();" method="post" class="form-horizontal">
				
				<div class="form-group">
					<label class="col-md-2 control-label" for="code">代码<span class='require'>*</span></label>
					<div class="col-md-8">
						<input type="text" id="code" name="code" class="form-control" />
					</div>
				</div>				
				<div class="form-group">
					<label class="col-md-2 control-label" for="question">题干<span class='require'>*</span></label>
					<div class="col-md-8">
						<textarea id="question" name="question"></textarea>
						<script type="text/javascript">
						    UE.getEditor('question');
						</script>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">类型</label>
					<div class="col-md-9">
						<volist name="type_list" id="vo">
							<label class="radio-inline">
								<input type="radio" id="type" name="type" value="{$vo.id}" <eq name="i" value="1">checked</eq> />&nbsp;{$vo.name}&nbsp;&nbsp;&nbsp;
							</label>
						</volist>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label">分数统计规则<span class='require'>*</span></label>
					<div class="col-md-9">
						<volist name="score_type_list" id="vo">
							<label class="radio-inline">
								<input type="radio" id="type" name="score_rule" value="{$vo.id}" <eq name="i" value="1">checked</eq> />&nbsp;{$vo.name}&nbsp;&nbsp;&nbsp;
							</label>
						</volist>
					</div>
				</div>
				<div class="form-group">
					<label class="col-md-2 control-label" for="score">分值<span class='require'>*</span></label>
					<div class="col-md-8">
						<input type="text" id="score" name="score" class="form-control" />
					</div>
				</div>
				<div class="general-option">
					<div class="form-group">
						<label class="col-md-2 control-label">选项<span class="require">*</span></label>
						<div class="col-md-8">
							<div class="input-group">
								<span class="input-group-addon option-move"><i class="glyphicon glyphicon-resize-vertical"></i></span>
								<input type="text" name="select_item[]" class="form-control" />
								<span class="input-group-addon">
									<label style="margin:0;">
										<input type="text" name="score_option[]" style="margin:0;padding:0;width:50px;height:20px;border:1px solid #e5e5e5;"/>&nbsp;分值
									</label>
								</span>
								<span class="input-group-addon">
									<label style="margin:0">
										<input type="checkbox" name="correct_option[]" />&nbsp;正确答案
										<input type="hidden" name="is_correct[]" value="a" />
									</label>
								</span>
								<span class="input-group-addon">
									<label style="margin:0">
										<input type="checkbox" name="mutual_option[]" />&nbsp;项内互斥
										<input type="hidden" name="is_mutual[]" value="a" />
									</label>
								</span>
							</div>
						</div>
						<div class="col-md-2">
							<p class="form-control-static">
								<a href="javascript:void(0)" onclick="plusGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="继续添加"><i class="fa fa-plus"></i></a>&nbsp;&nbsp;
								<a href="javascript:void(0)" onclick="minuGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="删除选项"><i class="fa fa-trash-o"></i></a>
							</p>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 control-label">选项<span class="require">*</span></label>
						<div class="col-md-8">
							<div class="input-group">
								<span class="input-group-addon option-move"><i class="glyphicon glyphicon-resize-vertical"></i></span>
								<input type="text" name="select_item[]" class="form-control" />
								<span class="input-group-addon">
									<label style="margin:0;">
										<input type="text" name="score_option[]" style="margin:0;padding:0;width:50px;height:20px;border:1px solid #e5e5e5;"/>&nbsp;分值
									</label>
								</span>
								<span class="input-group-addon">
									<label style="margin:0">
										<input type="checkbox" name="correct_option[]" />&nbsp;正确答案
										<input type="hidden" name="is_correct[]" value="a" />
									</label>
								</span>
								<span class="input-group-addon">
									<label style="margin:0">
										<input type="checkbox" name="mutual_option[]" />&nbsp;项内互斥
										<input type="hidden" name="is_mutual[]" value="a" />
									</label>
								</span>
							</div>
						</div>
						<div class="col-md-2">
							<p class="form-control-static">
								<a href="javascript:void(0)" onclick="plusGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="继续添加"><i class="fa fa-plus"></i></a>&nbsp;&nbsp;
								<a href="javascript:void(0)" onclick="minuGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="删除选项"><i class="fa fa-trash-o"></i></a>
							</p>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 control-label">选项<span class="require">*</span></label>
						<div class="col-md-8">
							<div class="input-group">
								<span class="input-group-addon option-move"><i class="glyphicon glyphicon-resize-vertical"></i></span>
								<input type="text" name="select_item[]" class="form-control" />
								<span class="input-group-addon">
									<label style="margin:0;">
										<input type="text" name="score_option[]" style="margin:0;padding:0;width:50px;height:20px;border:1px solid #e5e5e5;"/>&nbsp;分值
									</label>
								</span>
								<span class="input-group-addon">
									<label style="margin:0">
										<input type="checkbox" name="correct_option[]" />&nbsp;正确答案
										<input type="hidden" name="is_correct[]" value="a" />
									</label>
								</span>
								<span class="input-group-addon">
									<label style="margin:0">
										<input type="checkbox" name="mutual_option[]" />&nbsp;项内互斥
										<input type="hidden" name="is_mutual[]" value="a" />
									</label>
								</span>
							</div>
						</div>
						<div class="col-md-2">
							<p class="form-control-static">
								<a href="javascript:void(0)" onclick="plusGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="继续添加"><i class="fa fa-plus"></i></a>&nbsp;&nbsp;
								<a href="javascript:void(0)" onclick="minuGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="删除选项"><i class="fa fa-trash-o"></i></a>
							</p>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 control-label">选项<span class="require">*</span></label>
						<div class="col-md-8">
							<div class="input-group">
								<span class="input-group-addon option-move"><i class="glyphicon glyphicon-resize-vertical"></i></span>
								<input type="text" name="select_item[]" class="form-control" />
								<span class="input-group-addon">
									<label style="margin:0;">
										<input type="text" name="score_option[]" style="margin:0;padding:0;width:50px;height:20px;border:1px solid #e5e5e5;"/>&nbsp;分值
									</label>
								</span>
								<span class="input-group-addon">
									<label style="margin:0">
										<input type="checkbox" name="correct_option[]" />&nbsp;正确答案
										<input type="hidden" name="is_correct[]" value="a" />
									</label>
								</span>
								<span class="input-group-addon">
									<label style="margin:0">
										<input type="checkbox" name="mutual_option[]" />&nbsp;项内互斥
										<input type="hidden" name="is_mutual[]" value="a" />
									</label>
								</span>
							</div>
						</div>
						<div class="col-md-2">
							<p class="form-control-static">
								<a href="javascript:void(0)" onclick="plusGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="继续添加"><i class="fa fa-plus"></i></a>&nbsp;&nbsp;
								<a href="javascript:void(0)" onclick="minuGeneralOption(this)" class="highlight" data-toggle="tooltip" data-placement="top" title="删除选项"><i class="fa fa-trash-o"></i></a>
							</p>
						</div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="col-md-9 col-md-offset-2">
						<input type="hidden" name="formid" value="{$Think.request.formid}" />
						<input type="submit" value="保存" class="btn btn-primary" />&nbsp;&nbsp;
						<input type="button" onclick="history.go(-1)" value="返回" class="btn btn-green" />
					</div>
				</div>
			</form>
		</div>
	</div>
</block>